import logging
# 做日志的切分
import time
from logging import handlers
sh = logging.StreamHandler()
#                                           满了1024个字节保存     保留最近的五个文件
rh = handlers.RotatingFileHandler('myapp.log', maxBytes=1024,backupCount=5)   # 按照大小做切割
#                                                        按秒切       间隔5秒
fh = handlers.TimedRotatingFileHandler(filename='x2.log', when='s', interval=5, encoding='utf-8')
logging.basicConfig(
    format='%(asctime)s - %(name)s - %(levelname)s[line :%(lineno)d]-%(module)s:  %(message)s',
    datefmt='%Y-%m-%d %H:%M:%S %p',
    level= logging.DEBUG,
    # handlers=[fh,sh,fh2]
    handlers=[fh,rh,sh]
)
for i in range(1,100000):
    time.sleep(1)
    logging.error('KeyboardInterrupt error %s'%str(i))




